package com.jkgh.remedium.objects.messages {
	
	import com.jkgh.remedium.RemediumConstants;
	import com.jkgh.remedium.RemediumSystem;
	import com.jkgh.remedium.objects.RemediumObject;
	import com.jkgh.remedium.objects.messages.ins.RemediumS2CIntResponder;
	import com.jkgh.remedium.objects.messages.ins.RemediumS2CCaller;

	public class RemediumInMessage {
	
		protected var history:Vector.<RemediumObject>;
		
		public function RemediumInMessage() {
			this.history = new Vector.<RemediumObject>();
		}
	
		public static function recognize(remedium:RemediumSystem):RemediumInMessage {
			var messageType:int = remedium.produceByte();
			switch (messageType) {
			
				case RemediumConstants.S2C_INT_RESPONDER_TYPE:
					return new RemediumS2CIntResponder();
					
				case RemediumConstants.S2C_CALLER_TYPE:
					return new RemediumS2CCaller();
			}
			throw new Error("Unexpected message type "+messageType);
		}
	
		public function consumeContent(remedium:RemediumSystem, onDone:Function):void {
			throw new Error();
		}
		
		public final function fromHistory(index:int):RemediumObject {
			return history[index];
		}
	
		public final function toHistory(object:RemediumObject):void {
			history.push(object);
		}
		
	}	
}
